<template>
  <div class="rankings-view">
    <ul class="info-list">
      <list-template
        v-for="(item, index) of list.rows"
        :key="item.bookId"
        :item="item"
        :diff="'rankings-list'"
        :index="index + 1"
      />
    </ul>
    <div class="page-wrap">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page="params.pageNum"
        :page-size="params.pageSize"
        hide-on-single-page
        background
        layout="prev, pager, next"
        :total="list.total"
      >
      </el-pagination>
    </div>
    <div v-show="isEmpty" class="empty">
      <svg-icon class="empty-icon" icon-class="empty-search"></svg-icon>
      <p>No resources available</p>
    </div>
  </div>
</template>

<script>
import listTemplate from "@/components/common/listTemplate/Index";
export default {
  data() {
    return {
      list: {}, //书籍列表
      params: {
        pageNum: 1,
        pageSize: 20,
        id: this.$route.params.title,
      },
      scrollTop: 0,
      isEmpty: false,
    };
  },
  components: {
    listTemplate,
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    if (this.$route.params.title !== "null") {
      this.rankings();
    }
  },
  methods: {
    //当前页
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.rankings();
      this.backTop();
    },
    async rankings() {
      try {
        let res = await this.$api.home.rankings(this.params);
        if (res.code === 1) {
          this.list = res.source;
          if (res.source.total > 0) {
            this.isEmpty = false;
          } else {
            this.isEmpty = true;
          }
        }
      } catch (e) {
        console.log(e);
      }
    },
    backTop() {
      let timer = setInterval(() => {
        let ispeed = Math.floor(-this.scrollTop / 5);
        document.documentElement.scrollTop = document.body.scrollTop =
          this.scrollTop + ispeed;
        if (this.scrollTop === 0) {
          clearInterval(timer);
        }
      }, 50);
    },
  },
};
</script>

<style lang="scss" scoped>
.rankings-view {
  padding: 56px 0;
  .info-list {
  }
  > .empty {
    text-align: center;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    .empty-icon {
      width: 276px;
      height: 195px;
    }
    > p {
      margin-top: 41px;
      font-size: 14px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #999999;
      line-height: 20px;
      .toPage {
        cursor: pointer;
        text-decoration: underline;
        color: #e86472;
      }
    }
  }
}
</style>
